package sasku.client.core;

import java.io.File;

import org.apache.log4j.Logger;

public class Environment {
	
	public static final String VERSION = "0.1";

	private static Logger log = Logger.getLogger(Environment.class);
	private static final String settingsDirectory;

	static {
		log.debug("Loading environment settings");
		
		String operatingSystem = System.getProperty("os.name");
		String homeDirectory = System.getProperty("user.home");
		
		if ("Mac OS X".equals(operatingSystem)) {
			settingsDirectory = homeDirectory + "/Library/Sasku/";
		}
		else if ("Linux".equals(operatingSystem)) {
			settingsDirectory = homeDirectory + "/.sasku/";
		}
		else {
			settingsDirectory = homeDirectory + '/';
		}
		
		if (log.isDebugEnabled()) {
			log.debug("Operating System: " + operatingSystem);
			log.debug("Settings Directory: " + settingsDirectory);
		}
		
		checkSettingsDirectory();

	}
	
	private static void checkSettingsDirectory() {
		File dir = new File(settingsDirectory);
		if (!dir.exists()) {
			log.debug("Creating settings directory");
			if (!dir.mkdir()) {
				log.error("Failed to create settings directory [" + settingsDirectory + "]");
			}
		}
	}

	public static String getSettingsDirectory() {
		return settingsDirectory;
	}
}
